package Algorithm.Search.BinarySearchAndVariant.BinarySearch;

import java.util.Random;

public class Example {
    public static void main(String[] args) {
        Random rand = new Random();
        int[] arr = initialization();
        int num = rand.nextInt(100) + 1;
        System.out.println(Search(arr, num));
    }
    public static int[] initialization(){
        int[] arr = new int[100];
        for (int i = 1; i <= 100; i++)
            arr[i - 1] = i;
        return arr;
    }
    public static boolean Search(int[] arr, int target) {
        int low = 0;
        int high = arr.length - 1;
        while(arr[(low + high) / 2] != target){
            int middle = (low + high) / 2;
            if(arr[middle] > target){
                high = (low + high) / 2 - 1;
            } else if(arr[middle] < target){
                low = (low + high) / 2 + 1;
            }
            if (low > high){
                return false;
            }
        }
        return true;
    }
}
